import { Image, Rect } from "leafer-ui";
import { StaticBlack } from "./staticBlack";
import { DirectionType } from ".";
import { seedrandom } from "./webSoket";
import { AccelerateProp } from "./tankProps/accelerateProp";
import { AttackIntervalProp } from "./tankProps/attackIntervalProp";
import { AddHpProp } from "./tankProps/addHpProp";

export class Wall extends StaticBlack {
  health;
  constructor({ x, y, health = 3 }) {
    const qiang = new Rect({
      width: 50,
      height: 50,
      fill: {
        type: "image",
        url: "/qiang.gif",
        mode: "clip",
        scale: { x: 1, y: 1 },
      },
      x,
      y,
    });
    super({ x, y, width: 50, height: 50, targter: qiang, isRadiusPoint: true });
    if (health > 5) health = 5;
    this.health = health;
  }
  destroy({ mode, value }: { mode: DirectionType | null; value: number }) {
    this.health = this.health - value;
    if (this.health <= 0) {
      this.remove();
      const zhi = seedrandom?.rng();
      if (zhi <= 0.1) {
        new AccelerateProp({
          x: (this.targter.x || 0) + 10,
          y: (this.targter.y || 0) + 10,
        });
      } else if (zhi >= 0.9) {
        new AttackIntervalProp({
          x: (this.targter.x || 0) + 10,
          y: (this.targter.y || 0) + 10,
        });
      } else if (zhi >= 0.84) {
        new AddHpProp({
          x: (this.targter.x || 0) + 10,
          y: (this.targter.y || 0) + 10,
        });
      }
      return;
    }
  }
}
